#encoding=utf-8
import urllib2
import random

url = 'http://itcast.com'

ua_list = [
    'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
    'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
    'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0',
    'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)'
]
user_agent = random.choice(ua_list)

request = urllib2.Request(url)

request.add_header("User-Agent",user_agent)

request.get_header('User-Agent')

response = urllib2.urlopen(request)

html = response.read()

print html